#include "stdafx.h"
#include "LitEditorPolice.h"

namespace Lit
{
	namespace Editor
	{
		Police::Police( const std::string &family, int size, unsigned int modifier_flags, const QColor &col )
			: color( col )
		{ 
			font = QFont( TO_QT(family), size );
			setModifiers( modifier_flags );
		}
		Police::Police( const Police& rk ){ font = rk.font; color=rk.color; }
		Police::Police()
			: font("Times New Roman", 10), color( Qt::black )
		{}
		Police::Police( const QFont &font_, const QColor &col )
			: font( font_ ), color( col )
		{}
		Police& Police::operator = ( const Police& rk ){ font = rk.font; color=rk.color; return *this; }

		void Police::setModifiers( unsigned int modifier_flags )
		{ 
			setStrikeOut( (modifier_flags & StrikeOut)!=None );
			setUnderline( (modifier_flags & Underline)!=None );
			setItalic( (modifier_flags & Italic)!=None );
			setBold( (modifier_flags & Bold)!=None );
		}
		unsigned int Police::getModifiers() const{ 
			unsigned int ret = None;
			if( isItalic() ) ret |= Italic;
			if( isStrikeOut() ) ret |= StrikeOut;
			if( isBold() ) ret|= Bold;
			if( isUnderline() ) ret|=Underline;
			return ret;
		}
		
		std::string FontFamily::CourrierNew("Courier New");
		std::string FontFamily::TimesNewRoman("Times New Roman");
		std::string FontFamily::Arial("Arial");
		std::string FontFamily::ArialBlack("Arial Black");
		std::string FontFamily::Helvetica("Helvetica");
		std::string FontFamily::ComicSansMs("Comic Sans Ms");

		bool Police::isStrikeOut() const{ return font.strikeOut(); }
		bool Police::isUnderline() const{ return font.underline(); }
		bool Police::isItalic() const{ return font.italic(); }
		bool Police::isBold() const{return font.bold(); }

		void Police::setStrikeOut( bool strikeOut ){font.setStrikeOut( strikeOut ); }
		void Police::setUnderline( bool underLine ){font.setUnderline( underLine ); }
		void Police::setItalic( bool italic ){font.setItalic( italic ); }
		void Police::setBold( bool bold ){font.setBold( bold ); }
		
		LIT_API QTextCharFormat Police::textFormatFromPolice( const Police &pol )
		{
			QTextCharFormat fmt;
			fmt.setFont( pol.font );
			fmt.setForeground( pol.color );
			return fmt;
		}

		LIT_API Police Police::policeFromTextFormat( const QTextCharFormat& fmt )
		{
			Police pol;
			pol.color = fmt.foreground().color();
			pol.font = fmt.font();
			return pol;
		}
	};
};